package com.newjiabo.ski.service.impl;

import java.util.List;

import com.newjiabo.common.utils.DateUtils;
import com.newjiabo.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import com.newjiabo.ski.mapper.SkiSetMealServicesRelMapper;
import com.newjiabo.ski.domain.SkiSetMealServicesRel;
import com.newjiabo.ski.service.ISkiSetMealServicesRelService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 更多服务套餐关联Service业务层处理
 *
 * @author CaoMengHui
 * @date 2023-09-19
 */
@Service
public class SkiSetMealServicesRelServiceImpl implements ISkiSetMealServicesRelService {
    @Resource
    private SkiSetMealServicesRelMapper skiSetMealServicesRelMapper;

    /**
     * 查询更多服务套餐关联
     *
     * @param setMealId 更多服务套餐关联主键
     * @return 更多服务套餐关联
     */
    @Override
    public List<SkiSetMealServicesRel> selectSkiSetMealServicesRelBySetMealId(String setMealId) {
        return skiSetMealServicesRelMapper.selectSkiSetMealServicesRelBySetMealId(setMealId);
    }

    /**
     * 查询更多服务套餐关联列表
     *
     * @param skiSetMealServicesRel 更多服务套餐关联
     * @return 更多服务套餐关联
     */
    @Override
    public List<SkiSetMealServicesRel> selectSkiSetMealServicesRelList(SkiSetMealServicesRel skiSetMealServicesRel) {
        return skiSetMealServicesRelMapper.selectSkiSetMealServicesRelList(skiSetMealServicesRel);
    }

    /**
     * 新增更多服务套餐关联
     *
     * @param skiSetMealServicesRel 更多服务套餐关联
     * @return 结果
     */
    @Override
    public int insertSkiSetMealServicesRel(SkiSetMealServicesRel skiSetMealServicesRel) {
        skiSetMealServicesRel.setCreateTime(DateUtils.getNowDate());
        return skiSetMealServicesRelMapper.insertSkiSetMealServicesRel(skiSetMealServicesRel);
    }

    /**
     * 修改更多服务套餐关联
     *
     * @param skiSetMealServicesRel 更多服务套餐关联
     * @return 结果
     */
    @Override
    public int updateSkiSetMealServicesRel(SkiSetMealServicesRel skiSetMealServicesRel) {
        return skiSetMealServicesRelMapper.updateSkiSetMealServicesRel(skiSetMealServicesRel);
    }

    /**
     * 批量删除更多服务套餐关联
     *
     * @param setMealIds 需要删除的更多服务套餐关联主键
     * @return 结果
     */
    @Override
    public int deleteSkiSetMealServicesRelBySetMealIds(String[] setMealIds) {
        return skiSetMealServicesRelMapper.deleteSkiSetMealServicesRelBySetMealIds(setMealIds);
    }

    /**
     * 删除更多服务套餐关联信息
     *
     * @param setMealId 更多服务套餐关联主键
     * @return 结果
     */
    @Override
    public int deleteSkiSetMealServicesRelBySetMealId(String setMealId) {
        return skiSetMealServicesRelMapper.deleteSkiSetMealServicesRelBySetMealId(setMealId);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int bindingServices(List<SkiSetMealServicesRel> skiSetMealServicesRelList) {
        String setMealId = skiSetMealServicesRelList.get(0).getSetMealId();
        this.deleteSkiSetMealServicesRelBySetMealId(setMealId);
        // 初始化信息
        for (SkiSetMealServicesRel skiSetMealServicesRel : skiSetMealServicesRelList) {
            skiSetMealServicesRel.setCreateBy(SecurityUtils.getUsername());
        }
        this.saveBatch(skiSetMealServicesRelList);
        return 1;
    }

    public void saveBatch(List<SkiSetMealServicesRel> skiSetMealServicesRelList) {
        skiSetMealServicesRelMapper.saveBatch(skiSetMealServicesRelList);
    }
}
